/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.calculator;

import com.jy.appmarket.R;

import android.view.View;
import android.widget.RelativeLayout;

class EventListener implements View.OnClickListener, View.OnLongClickListener {
	Logic mHandler;

	void setHandler(Logic handler) {
		mHandler = handler;
	}

	// @Override
	public void onClick(View view) {
		int id = view.getId();
		switch (id) {
		case R.id.del:
			mHandler.onDelete();
			break;

		case R.id.equal:
			mHandler.onEnter();
			break;

		case R.id.clear:
			mHandler.onClear();
			break;

		default:
			if (view instanceof RelativeLayout) {
				String text = String.valueOf(getInputTextFromId(id));
				mHandler.insert(text);
			}
		}
	}

	private char getInputTextFromId(int id) {
		char text = ' ';
		switch (id) {
		case R.id.digit7:
			text = '7';
			break;
		case R.id.digit8:
			text = '8';
			break;
		case R.id.digit9:
			text = '9';
			break;
		case R.id.digit4:
			text = '4';
			break;
		case R.id.digit5:
			text = '5';
			break;
		case R.id.digit6:
			text = '6';
			break;
		case R.id.digit1:
			text = '1';
			break;
		case R.id.digit2:
			text = '2';
			break;
		case R.id.digit3:
			text = '3';
			break;
		case R.id.digit0:
			text = '0';
			break;
		case R.id.dot:
			text = '.';
			break;
		case R.id.equal:
			text = '=';
			break;
		case R.id.plus:
			text = '+';
			break;
		case R.id.minus:
			text = '\u2212';
			break;
		case R.id.mul:
			text = '\u00d7';
			break;
		case R.id.div:
			text = '\u00f7';
			break;
		default:
			break;
		}
		return text;
	}

	@Override
	public boolean onLongClick(View view) {
		return false;
	}
}
